package com.aispeech.testcustom.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

import com.aispeech.testcustom.i.GetValue;

/**
 * Created by rain on 2016/12/6.
 */
public class UiUtils {

    /**
     * 显示actionbar 的返回键 , 同时支持设置title
     *
     * @param ac
     * @param title
     */
    public static void showBack4ActionBar(AppCompatActivity ac, String title) {
        ActionBar mActionBar = ac.getSupportActionBar();
        mActionBar.setHomeButtonEnabled(true);
        mActionBar.setDisplayHomeAsUpEnabled(true);
        mActionBar.setTitle(title);
    }


    private static ProgressDialog mProgressBar;

    /**
     * 显示/关闭 转圈圈
     *
     * @param a       传入activity
     * @param b       true-显示/ false/关闭
     * @param title   标题头
     * @param content 内容显示
     */
    public static void showProgress(final Activity a, final boolean b, final String title, final
    String content) {

        a.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (b) {
                    //show
                    mProgressBar = ProgressDialog.show((Context) a, title, content);
                } else {
                    //dissmiss
                    if (null != mProgressBar) {

                        mProgressBar.dismiss();
                    }
                }
            }
        });

    }


    public static void showAlertDialog(Activity activity, String title, String msg, final
    GetValue getValue) {
        new AlertDialog.Builder(activity).setTitle(title).setMessage(msg)
                .setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //确定
                        getValue.getAlertDialogValue(true);
                    }
                })
                .setNegativeButton("否", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //添加返回按钮
                        getValue.getAlertDialogValue(false);
                    }
                }).show();
    }

}
